import logging
from   concurrent import futures

import grpc
import greeter_pb2
import greeter_pb2_grpc


class GreeterImpl(greeter_pb2_grpc.GreeterServicer):
    def sayHello(self, request, context):
        print(f"[Server]: name = {request.name}, age = {request.age}!")

        return greeter_pb2.Response(message=f"[Server]: \n\tname = {request.name},"
                                    " age = {request.age}!")


def serve():
    port   = "5555"
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))

    greeter_pb2_grpc.add_GreeterServicer_to_server(GreeterImpl(), server)
    server.add_insecure_port("[::]:" + port)
    server.start()

    print("Server started, listening on " + port)
    server.wait_for_termination()


if __name__ == "__main__":
    logging.basicConfig()
    serve()